package com.xgc.erp.report.outcome.ctrl;

import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.Db;
import com.xgc.common.base.BaseController;
import com.xgc.common.routes.ControllerBind;
import com.xgc.erp.report.outcome.service.OutcomeReportService;
import com.xgc.portal.echart.service.EchartService;
import com.xgc.portal.echart.vo.Chart;
import com.xgc.portal.echart.vo.EchartData;

import java.util.ArrayList;
import java.util.List;

@ControllerBind(path = "/erp/report/outcome")
public class OutcomeReportController extends BaseController {

    private EchartService service=EchartService.me;

    public void index(){
        render("index.html");
    }

    /**
     * 图表统计业务数据接口
     */
    public void reportPurchaseRate() {
        //TODO 根据具体业务给下面的变量赋值即可
        String title="按月统计采购情况";
        String subtitle="采购产品花费金额情况";
        String xAxis="entity_name";		//sql中的字段名
        String yAxis="sum_money";		//sql中的字段名
        String chartType="bar";	//bar,line,pie
        String xName="物品";
        String yName="金额（元）";
        String seriesName="采购金额";
        String tooltipText="";
        String sql = Db.getSql("erp.reportPurchaseRate");
        String month = get("month");
        month = month==null||month.equals("")?"2020-01":month;
        Object[] params=new Object[]{ month };
        Chart data =new Chart(title, subtitle, xAxis, yAxis, chartType, xName, yName, seriesName, tooltipText, sql, params);

        List<EchartData> list=new ArrayList<>();
        list.add(service.getEchartData(data));
        renderJson(list);
    }
}
